package io.renren.modules.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.modules.health.dao.SportDao;
import io.renren.modules.health.dto.SportDTO;
import io.renren.modules.health.entity.SportEntity;
import io.renren.modules.health.service.SportService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 运动热量维护
 *
 * @author Mark 
 * @since 1.0.0 2024-03-28
 */
@Service
public class SportServiceImpl extends CrudServiceImpl<SportDao, SportEntity, SportDTO> implements SportService {

    @Override
    public QueryWrapper<SportEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");
        String sportName = (String)params.get("sportName");
        List<Long> sportIds = (List<Long>) params.get("sportIds");
        Double bmi = (Double) params.get("bmi");

        QueryWrapper<SportEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);
        wrapper.like(StrUtil.isNotBlank(sportName), "sport_name", sportName);
        wrapper.in(!Objects.isNull(sportIds) && !sportIds.isEmpty(),"id",sportIds);
        wrapper.lt(bmi != null, "start_bmi", bmi).gt(bmi != null, "end_bmi", bmi);

        return wrapper;
    }


}